package Map;

import javax.swing.text.html.parser.Entity;
import java.util.*;
import java.util.function.Consumer;

public class MapDemo3 {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("语文",96);
        map.put("数学",95);
        map.put("英语",99);
        map.put("物理",90);
        map.put("化学",88);
        map.put(null,null);

        Set<String> keySet = map.keySet();
        System.out.println(keySet);
        for (String key : keySet){
            System.out.println(key);
        }
        System.out.println();
        Iterator iterator = keySet.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }

        Collection<Integer> values = map.values();
        for (Integer value : values){
            System.out.println(value);
        }

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        System.out.println(entrySet);
        for (Map.Entry<String,Integer> entry : entrySet){
            String key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println("key="+key+",value="+value);
        }

        keySet.forEach(k-> System.out.println(k));
        values.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.println(integer);
            }
        });
        entrySet.forEach(e-> System.out.println(e.getKey()+","+e.getValue()));
        map.forEach((k,v)-> System.out.println(k+","+v));

    }
}
